package basic;

/**
 * @Author: 海琳琦
 * @Date: 2021/9/6 17:24
 */
public class Title121 {
    public static void main(String[] args) {
        int[] prices = {1,2};
        System.out.println(maxProfit(prices));
    }

    private static int maxProfit(int[] prices) {
        int min=prices[0];
        int maxprofit=0;
        for (int i = 0; i < prices.length; i++) {
            if(prices[i]<min){
                min = prices[i];
            }else if(prices[i]-min>maxprofit){
                maxprofit=prices[i]-min;
            }
        }
        return maxprofit;
    }
}
